package io.github.source.media.bean;

import android.util.Log;

import com.google.gson.JsonElement;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Text;
import org.simpleframework.xml.core.Persister;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import androidx.annotation.Keep;
import io.github.source.Init;
import io.github.source.gson.FilterAdapter;

/**
 * #影视分类
 * 该分类的内容
 * 该分类的页面内容（荐片）
 * 该分类的过滤条件
 */
@Keep
@Root(strict = false)
public final class MediaCategory implements Serializable, Comparable<MediaCategory> {
    /**
     * 分类ID(唯一)
     */
    @Attribute(name = "id", required = false)
    @SerializedName(value = "type_id", alternate = "id")
    public String id;
    /**
     * 分类名称
     */
    @Text
    @SerializedName(value = "type_name", alternate = "name")
    public String name;
    /**
     * 排序标记
     */
    @SerializedName("sort")
    public int sort = -1;
    /**
     * 选中
     */
    @SerializedName("select")
    public boolean select = false;


    @SerializedName("type_flag")
    private String typeFlag;

    /**
     * 过滤数据
     */
    @SerializedName("filters")
    @JsonAdapter(FilterAdapter.class)
    private List<Filter> filters = new ArrayList<>();

    /**
     * 该分类下的媒体对象
     */
    @SerializedName("movie")
    private List<MediaBean> mediaBeans;

    @SerializedName("land")
    private int land;

    @SerializedName("circle")
    private int circle;
    /*显示比例*/
    @SerializedName("ratio")
    private float ratio;

    private Boolean filter;

    private boolean activated;

    /**
     * 选中的过滤条件
     */
    public HashMap<String, String> filterSelect = new HashMap<>();

    /**
     * site key（归属的源站点）
     */
    public String siteKey;

    public static MediaCategory objectXmlFrom(String element) {
        try {
            return new Persister().read(MediaCategory.class, element);
        } catch (Exception e) {
            return null;
        }
    }

    public static MediaCategory objectFrom(JsonElement element) {
        try {
            return Init.json().fromJson(element, MediaCategory.class);
        } catch (Exception e) {
            Log.d("TAG", "初始化json MediaCategory " + e);
            e.printStackTrace();
            return new MediaCategory();
        }
    }

    public static MediaCategory objectFrom(String element) {
        try {
            return Init.json().fromJson(element, MediaCategory.class);
        } catch (Exception e) {
            Log.d("TAG", "初始化json MediaCategory " + e);
            e.printStackTrace();
            return new MediaCategory();
        }
    }

    public String getSiteKey() {
        return siteKey;
    }

    public void setSiteKey(String siteKey) {
        this.siteKey = siteKey;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public boolean isSelect() {
        return select;
    }

    public void setSelect(boolean select) {
        this.select = select;
    }

    public String getTypeFlag() {
        return typeFlag;
    }

    public void setTypeFlag(String typeFlag) {
        this.typeFlag = typeFlag;
    }

    public List<Filter> getFilters() {
        return filters;
    }

    public void setFilters(List<Filter> filters) {
        this.filters = filters;
    }

    public List<MediaBean> getMediaBeans() {
        return mediaBeans;
    }

    public void setMediaBeans(List<MediaBean> mediaBeans) {
        this.mediaBeans = mediaBeans;
    }

    public int getLand() {
        return land;
    }

    public void setLand(int land) {
        this.land = land;
    }

    public int getCircle() {
        return circle;
    }

    public void setCircle(int circle) {
        this.circle = circle;
    }

    public float getRatio() {
        return ratio;
    }

    public void setRatio(float ratio) {
        this.ratio = ratio;
    }

    public Boolean getFilter() {
        return filter;
    }

    public void setFilter(Boolean filter) {
        this.filter = filter;
    }

    public boolean isActivated() {
        return activated;
    }

    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    @Override
    public int compareTo(MediaCategory category) {
        return this.sort - category.sort;
    }

    @Override
    public String toString() {
        return "MediaCategory{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", sort=" + sort + ", select=" + select + ", typeFlag='" + typeFlag + '\'' + ", filters=" + filters + ", mediaBeans=" + mediaBeans + ", land=" + land + ", circle=" + circle + ", ratio=" + ratio + ", filter=" + filter + ", activated=" + activated + ", filterSelect=" + filterSelect + ", siteKey='" + siteKey + '\'' + '}';
    }
}